<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>${_title}</title>

    <!-- Bootstrap core CSS -->

    <link href="${_css}/bootstrap.min.css" rel="stylesheet">

    <link href="${_font}/css/font-awesome.min.css" rel="stylesheet">
    <link href="${_css}/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="${_css}/custom.css" rel="stylesheet">
    <link href="${_css}/icheck/flat/green.css" rel="stylesheet">

    <!-- editor -->
    <link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" rel="stylesheet">
    <link href="${_css}/editor/external/google-code-prettify/prettify.css" rel="stylesheet">
    <link href="${_css}/editor/index.css" rel="stylesheet">

    <!-- switchery -->
    <link rel="stylesheet" href="${_css}/switchery/switchery.min.css" />

    <script src="${_js}/jquery.min.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->

</head>


<body style="background: #F7F7F7;">
<div class="">
    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>编辑单页面</h2>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">

                    <form class="form-horizontal form-label-left" novalidate>
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="title">标题 <span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                	<input id="title" class="form-control col-md-7 col-xs-12"
	                                name="title" placeholder="输入标题" required="required" type="text">
                            </div>
                        </div>
                        
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="author">访问链接<span class="required">*</span>
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                            	<input id="url" class="form-control col-md-7 col-xs-12"
	                                name="url" placeholder="输入访问链接" required="required" type="text">
                            </div>
                        </div>
						<div class="item form-group">
							<label class="control-label col-md-3 col-sm-3 col-xs-12" for="author">页面内容<span class="required">*</span>
                            </label>
					        <div class="col-md-9 col-sm-9 col-xs-12">
					                <div class="x_content">
					                    <div id="alerts"></div>
					                    <div class="btn-toolbar editor" data-role="editor-toolbar" data-target="#editor">
					                        <div class="btn-group">
					                            <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa icon-font"></i><b class="caret"></b></a>
					                            <ul class="dropdown-menu">
					                            </ul>
					                        </div>
					                        <div class="btn-group">
		                                        <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size">
		                                        	<i class="icon-text-height"></i>&nbsp;
		                                        	<b class="caret"></b>
		                                        </a>
		                                        <ul class="dropdown-menu">
		                                        	<li><a data-edit="fontSize 7"><p style="font-size:20px">x-large</p></a>
		                                            </li>
		                                            <li><a data-edit="fontSize 5"><p style="font-size:17px">Huge</p></a>
		                                            </li>
		                                            <li><a data-edit="fontSize 3"><p style="font-size:14px">Normal</p></a>
		                                            </li>
		                                            <li><a data-edit="fontSize 1"><p style="font-size:11px">Small</p></a>
		                                            </li>
		                                        </ul>
		                                    </div>
					                        <div class="btn-group">
					                            <a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
					                            <a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
					                            <a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="icon-strikethrough"></i></a>
					                            <a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
					                        </div>
					                        <div class="btn-group">
					                            <a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
					                            <a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
					                            <a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>
					                            <a class="btn" data-edit="indent" title="Indent (Tab)"><i class="icon-indent-right"></i></a>
					                        </div>
					                    </div>
					
					                    <div id="editor">
					                 	</div>
					            </div>
					        </div>                        
                        </div>
                        
                        <div class="item form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="order">备注
                            </label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                            	<input id="remark" class="form-control col-md-7 col-xs-12" value=""
	                                name="order" placeholder="输入备注" required="required" type="text">
                            </div>
                        </div>
                        
                    </form>
                </div>
            </div>
        </div>
    </div>
	</div>
	
    <div class="row">
		<div class="col-md-12 col-sm-12 col-xs-12" style="margin-bottom: 50px;">
		    <div class="ln_solid"></div>
		    <div class="form-group">
		        <div class="col-md-12 col-md-offset-5">
		            <button type="button" onclick="javascript:history.go(-1)" class="btn btn-primary">返回前一页</button>
			            <button id="save" type="button" class="btn btn-success">保存</button>
		        </div>
		    </div>			
		</div>
	</div> 
</div>
    <script src="${_js}/bootstrap.min.js"></script>
    <!-- bootstrap progress js -->
	<script src="${_js}/progressbar/bootstrap-progressbar.min.js" type="text/javascript"></script>
	<script src="${_js}/nicescroll/jquery.nicescroll.min.js" type="text/javascript"></script>
    <!-- icheck -->
    <script src="${_js}/icheck/icheck.min.js"></script>
    
	<script src="${_js}/custom.js" type="text/javascript"></script>
	<!-- dropzone -->
    <script src="${_js}/dropzone/dropzone.js" type="text/javascript" ></script>
    <!-- richtext editor -->
    <script src="${_js}/editor/bootstrap-wysiwyg.js"></script>
    <script src="${_js}/editor/external/jquery.hotkeys.js"></script>
    <script src="${_js}/editor/external/google-code-prettify/prettify.js"></script>
            
    <script type="text/javascript">

        $(function () {
            function initToolbarBootstrapBindings() {
                var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier',
            'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
            'Times New Roman', 'Verdana'],
                    fontTarget = $('[title=Font]').siblings('.dropdown-menu');
                $.each(fonts, function (idx, fontName) {
                    fontTarget.append($('<li><a data-edit="fontName ' + fontName + '" style="font-family:\'' + fontName + '\'">' + fontName + '</a></li>'));
                });
                $('a[title]').tooltip({
                    container: 'body'
                });
                $('.dropdown-menu input').click(function () {
                        return false;
                    })
                    .change(function () {
                        $(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');
                    })
                    .keydown('esc', function () {
                        this.value = '';
                        $(this).change();
                    });

                $('[data-role=magic-overlay]').each(function () {
                    var overlay = $(this),
                        target = $(overlay.data('target'));
                    overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
                });
                if ("onwebkitspeechchange" in document.createElement("input")) {
                    var editorOffset = $('#editor').offset();
                    $('#voiceBtn').css('position', 'absolute').offset({
                        top: editorOffset.top,
                        left: editorOffset.left + $('#editor').innerWidth() - 35
                    });
                } else {
                    $('#voiceBtn').hide();
                }
            };

            function showErrorAlert(reason, detail) {
                var msg = '';
                if (reason === 'unsupported-file-type') {
                    msg = "Unsupported format " + detail;
                } else {
                    console.log("error uploading file", reason, detail);
                }
                $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>' +
                    '<strong>File upload error</strong> ' + msg + ' </div>').prependTo('#alerts');
            };
            initToolbarBootstrapBindings();
            $('#editor').wysiwyg({
                fileUploadError: showErrorAlert
            });
            window.prettyPrint && prettyPrint();
        });
        
		$('#editor').wysiwyg();
		
		$("#save").click(function(){
			var content = $('#editor').html();
			var title = $.trim($("#title").val());
			var url = $.trim($("#url").val());
			var remark = $.trim($("#remark").val());
			var pageId = $("#pageId").val();
			
			var info=JSON.stringify({
				title:title,
				url:url,
				content:content,
				remark:remark
			});
			$.ajax({
	            type: 'POST',
	            dataType: 'JSON',
	            async:'false',
	            headers: {'Content-type': 'application/json;charset=UTF-8'},
	            url: '/admin/page/save',
	            data:info,
	            success: function(result){
	       		  if(result.code==-1){
	            		alert("修改成功!");
			        	window.location.href="/admin/page/list";
	       		  }else{
	            		alert(result.msg);       		  	
	       		  }
	            }
		    })	
			
		});
		
    </script>
</body>

</html>